#include <stdio.h>
#include <stdlib.h>
#include "camellia.h"
#include <time.h>
#include <inttypes.h>
int64_t timespecDiff(struct timespec *timeA_p, struct timespec *timeB_p)
{
	  return ((timeA_p->tv_sec * 1000000000) + timeA_p->tv_nsec) -
	             ((timeB_p->tv_sec * 1000000000) + timeB_p->tv_nsec);
}
int main(int argc, char* argv[])
{
	struct timespec start, end;
	CamImage source, down2xImage;
	camLoadBMP(&source, argv[1]);
	camAllocateRGBImage(&down2xImage, source.width/2, source.height/2);

	time_t beg = time(NULL);
	int i;
	const int iterations = 100;
	clock_gettime(CLOCK_MONOTONIC, &start);
	for( i=0; i < iterations; i++)
	{
		if(1!=camDownScaling2x2(&source, &down2xImage))
			printf("error\n");
	}
	clock_gettime(CLOCK_MONOTONIC, &end);
	uint64_t timeElapsed = timespecDiff(&end, &start);
	printf("%llu seconds for %d iterations\n", (unsigned long long) timeElapsed, iterations);

camSaveBMP(&down2xImage, argv[2]);

}
